let a: object  //a能存储的类型是【非原始类型】
let b: Object  //b能存储的类型是可以调用到Object方法的类型

a = {}
a = { name: '111' }
a = [1, 2, 3, 4]
a = function () { }
a = new String('123')
class Person { }
a = new Person()

// 以下代码 是将【原始类型】赋值给a，有警告
// a = 1          //Type 'number' is not assignable to type 'object'.ts
// a = true       //Type 'boolean' is not assignable to type 'object'.ts
// a = '你好'     //Type 'string' is not assignable to type 'object'
// a = null       //Type 'null' is not assignable to type 'object'
// a = undefined  //Type 'undefined' is not assignable to type 'object'

b = {}
b = { name: '111' }
b = [1, 2, 3, 4]
b = function () { }
b = new String('123')
b = new Person()
b = 1
b = true
b = '你好'

// b = null  //Type 'null' is not assignable to type 'Object'
// b = undefined  //Type 'undefined' is not assignable to type 'Object'

/**
 * Object
 * 官方描述:所有可以调用Object方法
 * 简单:除了null和undefined的任何值
 */


let person: {
    name: string,
    age?: number, // "?"让字段可选
    [key: string]: any; //后面接任意string字段  "key"可随意更改
    [k: number]: any;//后面接任意number字段  "k"可随意更改
    [index: symbol]: any;//后面接任意symbol字段   "index"可随意更改
}
person = { name: '11', level: '123', aa: 123 }


// 函数  可以定义 变量类型和返回值类型
let count: (a: number, b: number) => number

count = function (a, b) {
    // return a + b + 'string' //Type 'string' is not assignable to type 'number'
    return a + b
}

// 数组类型
let arr1: string[]
let arr2: Array<number>  //泛型
// arr = ['a', 'b', 100]  //Type 'number' is not assignable to type 'string'
arr1 = ['a', 'b']
arr2 = [100, 200]

console.log(arr1, arr2)



